package pCloud.message;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;

/**
 * Objects from this class are indices for the cache implemented at the Proxy server.
 * Therefore, the hash code and equality check do not take requestID into account
 * @author anhdinh
 *
 */
public class RequestFile extends SocketFile {
	
	int requestId;
	String joiningColumn;
	InetSocketAddress serverAddress;
	
	public RequestFile(int id, String column, InetSocketAddress serverAddress) {
		this.type = SocketFile.REQUEST_FILE;
		this.requestId = id;
		this.joiningColumn = column;
		this.serverAddress = serverAddress;
	}
	
	public int getRequestId(){
		return this.requestId;
	}
	
	public String getJoiningColumn(){
		return this.joiningColumn;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((joiningColumn == null) ? 0 : joiningColumn.hashCode());
		result = prime * result
				+ ((serverAddress == null) ? 0 : serverAddress.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		RequestFile other = (RequestFile) obj;
		if (joiningColumn == null) {
			if (other.joiningColumn != null)
				return false;
		} else if (!joiningColumn.equals(other.joiningColumn))
			return false;
		if (serverAddress == null) {
			if (other.serverAddress != null)
				return false;
		} else if (!serverAddress.equals(other.serverAddress))
			return false;
		return true;
	}

	
}
